<template>
  <div>
    <el-table
      :data="tableData"
      border
      style="width: 100%">
      <el-table-column
        prop="date"
        label="日期"
        width="180">
      </el-table-column>
      <el-table-column
        prop="name"
        label="姓名"
        width="180">
      </el-table-column>
      <el-table-column
        prop="address"
        label="地址">
      </el-table-column>
    </el-table>
    <!--
      el-pagination:elementui自定义的分页组件
      background：背景
      layout：布局
      :total：总条数

    -->
    <el-pagination
      background
      layout="prev, pager, next"
      :total=totals
      align="right"
      :page-size=pageSize
      :current-page=currentPage
      @current-change="changePage">
    </el-pagination>
  </div>
</template>

<script>
export default {
  name: 'MyTable',
  data() {
    return {
      totals: 100,
      pageSize: 5,
      currentPage: 1,
      tableData: [{
        date: '2016-05-02',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1518 弄'
      }, {
        date: '2016-05-04',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1517 弄'
      }, {
        date: '2016-05-01',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1519 弄'
      }, {
        date: '2016-05-03',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1516 弄'
      }
        , {
          date: '2016-05-03',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1516 弄'
        }
        , {
          date: '2016-05-03',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1516 弄'
        }
        , {
          date: '2016-05-03',
          name: '王小虎',
          address: '上海市普陀区金沙江路 1516 弄'
        }]
    }
  },
  methods: {
    // 监听页码变化函数
    changePage(curr) {
      this.currentPage = curr;
    },
    // 调用后端接口获取列表数据
    getUsers() {
      // 发送axios请求获取后端数据
      this.$http.post("/user/list", {"pageSize": this.pageSize, "currentPage": this.currentPage})
        .then(reuslt => {
          // 请求成功 有数据返回
          this.tableData = result.data.rows
          this.totals = result.data.totals
        })

    }
  }
}
</script>

<style scoped>

</style>
